<template>
  <el-card shadow="hover">
    <template #header>
      <div class="card-header">
        <el-button class="button" color="#1baeae">+ 增加</el-button>
        <el-button class="button" color="#f56c6c" :icon="Delete">批量删除</el-button>
      </div>
    </template>
    <el-table ref="multipleTableRef" :data="state.tableData" style="width: 100%"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" />
      <el-table-column property="categoryName" label="分类名称" />
      <el-table-column property="categoryRank" label="排序值" />
      <el-table-column label="排序时间">
        <template #default="scope">{{ scope.row.createTime }}</template>
      </el-table-column>
      <el-table-column label="操作" min-width="20%">
        <template slot-scope="{ row }">
          <el-link type="success" @click="update(row)">修改</el-link>
          <el-popconfirm
            title="确定要删除本条数据吗？"
            @confirm="remove([row.id])"
          >
            <el-link type="primary" slot="reference">删除</el-link>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background layout="prev, pager, next" :total="state.total" :current-page="state.currentPage"
      :page-size="state.pageSize" />
  </el-card>
</template>

<script>
  export default {
    name: 'classifyAdministration',
  }
</script>
<script setup>
  import {
    Delete
  } from '@element-plus/icons-vue'
  import api from '@/http'
  import {
    reactive,
    onBeforeMount
  } from "vue"
  import {
    ElMessage
  } from 'element-plus'
  const state = reactive({
    tableData: [],
    total: 0,
    pageSize: 10,
    currentPage: 1,
  })
  onBeforeMount(async () => {
    const {
      data,
      resultCode
    } = await api.classify.categories(state.currentPage, state.pageSize, 1, 0);
    if (resultCode === 200) {
      state.tableData = data.list;
      state.total = data.totalCount;
      state.pageSize = data.pageSize
    } else {
      ElMessage({
        showClose: true,
        message: '数据渲染失败，请稍后再试！！',
        type: 'error',
      })
    }
  })
</script>

<style lang="less" scoped>
  .button {
    color: #fff;
  }
</style>